'''
#1
def main():
    lst1=[]
    n=int(input("请输入一个整数:"))
    lst2=input().split(' ')
    for i in range(n):
        lst1.append(int(lst2[i]))
    lst1.sort()
    for num in lst1:
        print(num,end=' ')
main()

def main():
    n =int(input())
    lst1=[]
    for i in range(n):
        num1=input()
        lst1.append(num1)
    for num2 in lst1:
        print('{:o}'.format(int(('0x'+num2),16)))
main()


#
def BubbleSort(n,num):
    while n<=1:
        return num
    for i in range(0,n):
        for j in range(0,n-i-1):
            if num[j]>num[j+1]:
                num[j],num[j+1]=num[j+1],num[j]
    return num
    
n=int(input())
num = input().split()

for i in range(n):
    num [i] = int(num [i])

BubbleSort(n,num)
for each in num:
    print(each,end=' ')
    
'''
n =int(input())
x =[]
for i in range(n):
    x.append(oct(int(input(),16)))
    #oct:八进制
for i in x:
    print(i[2:])
